package com.b2c.ftysys.dao;

import java.util.List;
import java.util.Map;

import com.b2c.ftysys.domain.PageResult;
import com.ibatis.sqlmap.client.SqlMapClient;

public interface IDBUtils<T> {

	public Map<String, T> getMap(String sqlName, Object paramObject, String keyProp)
			throws DatabaseException;

	/**
	 * get the list of result objects.
	 * 
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * @return the list of result objects.
	 * 
	 */
	public List<T> getList(String sqlname) throws DatabaseException;

	/**
	 * get the list of result objects.
	 * 
	 * @param o
	 *            parameter object
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * @return the list of result objects.
	 * 
	 */
	public List<T> getList(Object param, String sqlname) throws DatabaseException;

	/**
	 * Executes a mapped SQL SELECT statement that returns data to populate a
	 * number of result objects within a certain range.
	 * 
	 * @param o
	 *            parameter object
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * @param offset
	 *            The number of results to ignore.
	 * @return the list of result objects.
	 * 
	 */
	public List<T> getListPage(Object param, String sqlname, int offset, int pageSize)
			throws DatabaseException;
	
	public List<T> getListPage(String sqlname, int offset, int pageSize)
	throws DatabaseException;
	
	/**
	 * 标准的分页方法,需定义offset
	 * @param page
	 * @return
	 * @throws DatabaseException
	 */
	public PageResult getListByPage(PageResult page) throws DatabaseException;

	/**
	 * 
	 * Executes a mapped SQL SELECT statement that returns data to populate a
	 * single object instance.
	 * 
	 * @param id
	 *            the id
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * @return the result objects.
	 * 
	 */
	public T queryWithId(Object id, String sqlName) throws DatabaseException;

	/**
	 * 
	 * Executes a mapped SQL SELECT statement that returns the count of this
	 * result
	 * 
	 * @param param
	 *            the parameter object
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * @return the count of this result.
	 * 
	 */
	public int getCountForPage(Object param, String sqlName)
			throws DatabaseException;

	/**
	 * 
	 * Executes a mapped SQL SELECT statement that returns data to populate a
	 * single object instance.
	 * 
	 * @param o
	 *            parameter object
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * @return the result objects.
	 * 
	 */
	public T getObject(Object param, String sqlName) throws DatabaseException;

	/**
	 * Executes a mapped SQL SELECT statement that returns data to populate the
	 * supplied result object.
	 * 
	 * @param param
	 *            parameter object
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * @param The
	 *            result object instance that should be populated with result
	 *            data.
	 * @return the result objects.
	 * 
	 */
	public T getObject(Object param, String sqlName, T resultObject)
			throws DatabaseException;

	/**
	 * Executes a mapped SQL SELECT statement that returns data to populate the
	 * supplied result object.
	 * 
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * @param The
	 *            result object instance that should be populated with result
	 *            data.
	 * @return the result objects.
	 * 
	 */
	public T getObject(String sqlName) throws DatabaseException;

	/**
	 * Executes a mapped SQL UPDATE statement.
	 * 
	 * @param param
	 *            parameter object
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * 
	 * @exception DatabaseException
	 * 
	 */
	public int update(T param, String sqlname) throws DatabaseException;

	/**
	 * Executes a mapped SQL INSERT statement.
	 * 
	 * @param param
	 *            parameter object
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * 
	 * @exception DatabaseException
	 */
	public int save(T param, String sqlname) throws DatabaseException;

	/**
	 * Executes a mapped SQL DELETE statement.
	 * 
	 * @param param
	 *            parameter object
	 * @param sqlname
	 *            The name of the statement to execute(mapped in the sql xml).
	 * 
	 * @exception DatabaseException
	 */
	public int delete(T param, String sqlname) throws DatabaseException;
	public int deleteByObject(Object param, String statementName) throws DatabaseException;
	public SqlMapClient getSqlClient();
	
	/**
	 * 获取下一个自增ID
	 * @param tableName 表名
	 * @return
	 * @throws DatabaseException 
	 */
	Long getAutoIncrementId(String tableName) throws DatabaseException;
}
